// 查询
button_query_onclick = function() {
	efgrid.submitInqu("ef_grid_result", "ZM", "ZMCK20", "query");
};
// 新增
button_insert_onclick = function() {
	var grid = isSelected("ef_grid_result");
	if (grid == 0)
		return;
	
	var rows = grid.getCheckedRows();
	for (var i = 0; i < rows.length; i++) {
		var fdVirtualDate = grid.getCellValueByColumnName(rows[i], "fdVirtualDate");
		var day = getNowDate();
		if (getDateValue(fdVirtualDate) > getDateValue(day)) {
			EFAlert("调度日期不能晚于当前日期，请重新输入！");
			return;
		}
	}
	efgrid.submitForm("ef_grid_result", "ZM", "ZMCK20", "insert", true);
};
// 修改
button_update_onclick = function() {
	var grid = isSelected("ef_grid_result");
	if (grid == 0)
		return;

	var rows = grid.getCheckedRows();
	for (var i = 0; i < rows.length; i++) {
		if (grid.getCellValueByColumnName(rows[i], "fdStatus") != "草拟") {
			EFAlert("只能对草拟的记录进行修改！");
			return;
		}
		
		var fdVirtualDate = grid.getCellValueByColumnName(rows[i], "fdVirtualDate");
		var day = getNowDate()
		if (getDateValue(fdVirtualDate) > getDateValue(day)) {
			EFAlert("调度日期不能晚于当前日期，请重新输入！");
			return;
		}
	}
	efgrid.submitForm("ef_grid_result", "ZM", "ZMCK20", "update", true);
};
// 删除
button_delete_onclick = function() {
	var grid = isSelected("ef_grid_result");
	if (grid == 0)
		return;

	var rows = grid.getCheckedRows();
	for (var i = 0; i < rows.length; i++) {
		if (grid.getCellValueByColumnName(rows[i], "fdStatus") != "草拟") {
			EFAlert("只能对草拟的记录进行删除！");
			return;
		}
	}

	EFConfirm('你确认要删除吗?', '确认框',
			function(r) {
				if (r)
					efgrid.submitForm("ef_grid_result", "ZM", "ZMCK20",
							"delete", true);
			});
};
// 上报
button_report_onclick = function() {
	var grid = isSelected("ef_grid_result");
	if (grid == 0)
		return;

	var rows = grid.getCheckedRows();
	if (rows.length > 1) {
		EFAlert("一次只能上报一条记录！", "警告");
		return;
	}
	for (var i = 0; i < rows.length; i++) {
		if (grid.getCellValueByColumnName(rows[i], "fdStatus") != "草拟") {
			EFAlert("只能上报草拟状态的记录！", "警告");
			return;
		}
		if (grid.getCellValueByColumnName(rows[i], "fdKeyId") == "") {
			EFAlert("该记录不存在，请先新增后再上报！", "警告");
			return;
		}
	}

	EFConfirm('确认要上报吗?', '确认框',
			function(r) {
				if (r)
					efgrid.submitForm("ef_grid_result", "ZM", "ZMCK20",
							"report", true);
			});
};
efgrid_afterAddNewRow = function(grid_id) {
	var grid = efgrid.getGridObject(grid_id);
	var rows = grid.getCheckedRows();
	if (grid_id == "ef_grid_result") {
		var fdMiningName = $('#fdMiningName').val();
		var fdCreateDepartmentId = $('#fdCreateDepartmentId').val();
		var fdCreator = $('#fdCreator').val();
		var day = getNowDate(); // 日
		var time = getNowDateTime();// 当前时间

		for (var i = 0; i < rows.length; i++) {
			grid.getBlockData().setCell(rows[i], "fdKeyId", "");
			grid.getBlockData().setCell(rows[i], "fdStatus", "草拟"); // 状态
			grid.getBlockData().setCell(rows[i], "fdMiningName", fdMiningName);// 矿井名称
			grid.getBlockData().setCell(rows[i], "fdReportDepartmentId", fdCreateDepartmentId);// 汇报部门
			grid.getBlockData().setCell(rows[i], "fdReportPerson", fdCreator);// 汇报人
			grid.getBlockData().setCell(rows[i], "fdCurrentDate", day);// 当前日期
			grid.getBlockData().setCell(rows[i], "fdVirtualDate", day);// 调度日期
			grid.getBlockData().setCell(rows[i], "fdLocationTime", time);// 下井时间
		}
	}
};
/*
根据传入的String类型的date获取该日期对应的毫秒值，传入的字符串格式为：yyyy-MM-dd HH:mm:ss
*/
function getDateValue(dateStr) {
   var tt = dateStr.split(" ");
   var ttt1 = tt[0].split("-");
   var date1 = new Date(ttt1[0], ttt1[1], ttt1[2]);
   var m1 = date1.getTime();
   return m1;
};